﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Data;
using System.Drawing;
using System.Windows.Forms;
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.Serialization;

namespace CH_k
{
    [Serializable]
    public class OR : LoElement
    {
        public OR(bool _invers = false)
        {
            input_n = 2;
            size = new Point(20, 30);
            invers = _invers;
            ElType = invers ? "NOR" : "OR";
        }

        public override bool Run()
        {
            if (!alreadyRun)
            {
                alreadyRun = true;
                bool trez = false;
                for (int i = 0; i < input_n; i++)
                {
                    if(inElList[i] != null)
                    {
                        if (inElList[i].Run())
                        {
                            trez = true;
                        }
                    }
                }
                oldState = trez;
                if (invers) oldState = !oldState;
                return oldState;
            }
            else
            {
                return oldState;
            }
        }
       
        public override void Draw(Graphics _g)
        {
            if (cPen == null) cPen = new Pen(Color.Black);
            for (int i = 0; i < input_n * 10; i += 10)
            {
                _g.DrawLine(cPen, new Point(dec.X, dec.Y + 10 + i), new Point(dec.X + 10, dec.Y + 10 + i));
            }
            _g.DrawRectangle(cPen, dec.X + 10, dec.Y, 20, 10 + input_n * 10);
            _g.FillRectangle(Brushes.LightGray, dec.X + 11, dec.Y + 1, 19, 9 + input_n * 10);
            _g.DrawString("1", new Font("Arial", 12), Brushes.Black, new Point(dec.X + 12, dec.Y));
            _g.DrawLine(cPen, new Point(dec.X + 30, dec.Y + 10), new Point(dec.X + 40, dec.Y + 10));
            if (invers)
            {
                _g.FillEllipse(Brushes.White, dec.X + 27, dec.Y + 7, 6, 6);
                _g.DrawEllipse(cPen, dec.X + 27, dec.Y + 7, 6, 6);
            }
        }
    }
}
